//基础路径
var base = document.getElementById('testScript').getAttribute('base');

var app=new Vue({
    el:"#app",
    data(){
        return{
            //用户名
            username:'',
            //密码
            password:'',
            //是否记住密码
            remember:false,
            //错误信息
            usernameError:'',
            passwordError:''

        }
    },
    methods:{
        //登陆
        login:function () {
            var _t=this;
            var params={
                username:this.username,
                password:this.password,
                remember:this.remember
            };
            this.clean();
            axios.post(base + "/users/login",params)
                .then(function (response) {
                    if (response.data.code === 200) {
                        window.location.href=base+'';
                    }else {
                        if (response.data.message === '用户名不存在') {
                            _t.usernameError=response.data.message;
                        }else if (response.data.message === '密码错误'){
                            _t.passwordError=response.data.message;
                        }
                    }
                });
        },
        //注册
        register:function () {
            window.location.href=base+'/user/register'
        },
        //清空错误提示
        clean:function () {
            this.usernameError='';
            this.passwordError='';
        }
    }
});